package edu.colorado.csci3308.ekwhite.code;

import java.io.IOException;

	import javax.servlet.http.HttpServlet;
	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	import javax.servlet.Servlet;
	import javax.servlet.ServletException;


	public class BackwardCardServlet extends HttpServlet implements Servlet {

		private static final long serialVersionUID = 1L;

		@Override
		protected void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			
			// check to see if information already exists from user's previous interactions with the page
			StudentsInCourse cardList = (StudentsInCourse) request.getSession(true).getAttribute("currentCardList");
			if(cardList == null)
			{
				cardList = new StudentsInCourse();
				cardList.createDefaultList();
			}
			Integer index = (Integer) request.getSession(true).getAttribute("currentCard");
			if (index == null) 
			{
				index = 0;
			}
			else --index;
			
			// now we forward this back to the JSP
			request.getSession().setAttribute("currentCardList", cardList);
			request.getSession().setAttribute("currentCard", index);
			getServletContext().getRequestDispatcher("/LookAtFaces.jsp").forward(request, response);

		}

	}
